package main
/*
#cgo CFLAGS:--sysroot /Users/chenxin/Library/Android/sdk/ndk-bundle/platforms/android-19/arch-arm -I/Users/chenxin/Library/Android/sdk/ndk-bundle/platforms/android-19/arch-arm/usr/include
#cgo LDFLAGS:-L/Users/chenxin/Library/Android/sdk/ndk-bundle/platforms/android-19/arch-arm/usr/lib -llog -landroid
#include <jni.h>
//#include <pthread.h>
#include <android/log.h>
*/
import "C"
import (
	"bufio"
	"./socketio_client"
	"log"
	"os"
	"fmt"
)

func main() {

	opts := &socketio_client.Options{
		Transport: "websocket",
		Query:     make(map[string]string),
	}
	opts.Query["imei"] = "865009020325127"
	uri := "http://127.0.0.1:7071/socket.io/"

	client, err := socketio_client.NewClient(uri, opts)
	if err != nil {
		log.Printf("NewClient error:%v\n", err)
		return
	}

	client.On("error", func() {
		log.Printf("on error\n")
	})
	client.On("connection", func() {
		log.Printf("on connect\n")
	})
	client.On("message", func(msg string) {
		log.Printf("on message:%v\n", msg)
	})
	client.On("disconnection", func() {
		log.Printf("on disconnect\n")
	})

	reader := bufio.NewReader(os.Stdin)
	for {
		data, _, _ := reader.ReadLine()
		command := string(data)
		client.Emit("message", command)
		log.Printf("send message:%v\n", command)
	}
}
//export Java_cn_forke_speex_media_PTT_play
func Java_cn_forke_speex_media_PTT_play(env *C.JNIEnv, clazz C.jclass) C.jint {
	fmt.Println("Hello from Go");
	//return GetVersion(env)
	return 1
}
//export Java_cn_forke_speex_media_PTT_stop
func Java_cn_forke_speex_media_PTT_stop(env *C.JNIEnv, clazz C.jclass) C.jint {
	fmt.Println("Hello from Go");
	return 1
}
//, x C.jlong, y C.jlong
